﻿using System;
using Volo.Abp;
using Xms.Abp.MultiTenancy;

namespace TenantManagement;

[Serializable]
[Volo.Abp.MultiTenancy.IgnoreMultiTenancy]
public class TenantCacheItem
{
    private const string CacheKeyFormat = "TenantInfo:{0}";

    public TenantData Value { get; set; }

    public TenantCacheItem()
    {

    }

    public TenantCacheItem(TenantData value)
    {
        Value = value;
    }

    public static string CalculateCacheKey(Guid? id, string name)
    {
        if (id == null && name.IsNullOrWhiteSpace())
        {
            throw new AbpException("Both id and name can't be invalid.");
        }

        return id != null ? string.Format(CacheKeyFormat, id?.ToString() ?? "Host") : string.Format(CacheKeyFormat, name);
    }
}
